<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath %>">
    <title>可退货列表管理</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <%-- 引用layui.css --%>
    <link rel="stylesheet" type="text/css" href="<%=basePath %>js/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath %>css/common.css"/>
</head>
<body>
<div class="ibox">
    <div class="ibox-content bodycss">
        <!-- 表单搜索 开始 -->
        <section class="panel panel-padding ">
            <form class="layui-form layui-form-pane form-search"
                  onsubmit="return false" method="get">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">订单编号</label>
                    <div class="layui-input-inline">
                        <input name="orderSn" id="orderSn" value="" placeholder="请输入订单编号(tvn)"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">会员名称</label>
                    <div class="layui-input-inline">
                        <input name="userName" id="userName" value="" placeholder="请输入会员名称"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">会员卡号</label>
                    <div class="layui-input-inline">
                        <input name="userCardNumber" id="userCardNumber" value="" placeholder="请输入会员卡号"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">会员电话</label>
                    <div class="layui-input-inline">
                        <input name="receiverPhone" id="receiverPhone" value="" placeholder="请输入会员电话"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">订单状态</label>
                    <div class="layui-input-inline">
                        <div style="width:150px">
                            <select name="orderState" id="orderState">
                                <!-- 订单状态：0:已取消;10(默认):待确认;20:已确认;30:已配货;40:已发货;50:已收款;60:已退货 -->
                                <option value="">请选择</option>
                                <option value="30">已配货</option>
                                <option value="40">已发货</option>
                                <option value="50">已收款</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="layui-btn layui-btn-primary" lay-submit lay-filter="search">
                        <i class="layui-icon"></i> 搜 索
                    </button>
                </div>
            </form>
        </section>
        <!-- 表单搜索 结束 -->
        <section class="panel panel-padding ">
            <c:if test="${sessionScope.userpopedom.ddgl03xcel eq '1' }"> <!-- pagecontext request session application -->
                <div class="ibox-toolbar">
                    <button id="exportExcel" data-modal="" data-title="导出Excel"
                            class="layui-btn layui-btn-sm">
                        <i class="layui-icon">&#xe667;</i> 导出Excel
                    </button>
                </div>
            </c:if>
            <table class="layui-table" id="tableReload" lay-filter="popedomLay"></table>

        </section>
    </div>
</div>
<%--收货方式(0：上门送，1：自取)--%>
<script type="text/html" id="receipt_Method">
    {{#  if(d.receiptMethod == "0") {  }}
    <font color="#00ff00">上门送</font>
    {{#  } else if(d.receiptMethod == "1") {  }}
    <font color="#ff0000">自取</font>
    {{#  }  }}
</script>

<script type="text/html" id="goods_Type">
    <%--商品属性（0:正品;1:打折;2:体验;3:积分兑换;4:用来打包;5:打包品7:可兑换打包品)--%>
    {{#  if(d.goodsType == "0") {  }}
    <font color="#00ff00">正品</font>
    {{#  } else if(d.goodsType == "1") {  }}
    <font color="#ff0000">打折品</font>
    {{#  } else if(d.goodsType == "2") {  }}
    <font color="#ff0000">体验品</font>
    {{#  } else if(d.goodsType == "3") {  }}
    <font color="#ff0000">积分兑换品</font>
    {{#  } else if(d.goodsType == "4") {  }}
    <font color="#ff0000">用来打包品</font>
    {{#  } else if(d.goodsType == "5") {  }}
    <font color="#ff0000">打包品</font>
    {{#  } else if(d.goodsType == "7") {  }}
    <font color="#ff0000">可兑换打包品</font>
    {{#  }  }}

</script>
<%--订单状态：0:已取消;10(默认):待确认;20:已确认;30:已配货;40:已发货;50:已收款;60:已退货--%>
<script type="text/html" id="order_State">


    {{#  if(d.orderState == "30") {  }}
    <font color="#ff0000">已配货</font>
    {{#  } else if(d.orderState == "40") {  }}
    <font color="#ff0000">已发货</font>
    {{#  } else if(d.orderState == "50") {  }}
    <font color="#ff0000">已收款</font>

    {{#  }  }}


</script>

<script type="text/html" id="popedomBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="toDetail">订单退货</a>
</script>

<script type="text/javascript" src="<%=basePath %>js/layui/layui.js"></script>
<script type="text/javascript">
    layui.config({
        base: "<%=basePath%>js/common/"
    }).use(["common", "element", "layer", "form", "table", "jquery"], function () {
        var elem = layui.element;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        layui.common.init();


        table.render({
            elem: "#tableReload"
            , width: 'auto'
            , url: 'DDGL060/list.do'
            , page: true
            , even: true
            , skin: 'row'
            , limits: [10, 20, 30, 40, 50]
            , limit: 10
            , cols: [[
                {type: 'numbers', title: '序号', width: 100}
                , {field: 'orderSn', title: '订单编号', width: 200, align: 'center'}
                , {field: 'userName', title: '会员名称', width: 120, align: 'center'}
                , {field: 'goodsName', title: '商品名称', width: 120, align: 'center'}
                , {field: 'goodsNum', title: '商品数量', width: 100, align: 'center'}
                , {field: 'specifications', title: '商品规格', width: 150, align: 'center'}
                , {field: 'goodsType', title: '商品属性', width: 120, align: 'center', templet: '#goods_Type'}
                , {field: 'userCardNumber', title: '会员卡号', width: 120, align: 'center'}
                , {field: 'receiverPhone', title: '会员电话', width: 120, align: 'center'}
                , {field: 'orderAmount', title: '订单金额(￥)', width: 150, align: 'center'}
                , {field: 'returnCost', title: '退货费用(￥)', width: 120, align: 'center'}
                , {field: 'orderState', title: '订单状态', width: 120, align: 'center', templet: '#order_State'}
                , {field: 'receiptMethod', title: '收货方式', width: 100, align: 'center', templet: '#receipt_Method'}
                , {field: 'receiverAddress', title: '收货地址', width: 250, align: 'center'}
                , {field: 'addTime', title: '订单生成时间', width: 200, align: 'center'}
                , {field: 'orderId', title: '订单id', width: 120, align: 'center'}
                , {fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#popedomBar'}
            ]]
            , done: function (res) {
                //console.log(res); //接口返回信息
                var data = res.data;
                /*隐藏列*/
                $("[data-field='orderId']").css('display', 'none');
                $("[data-field='returnCost']").css('display', 'none');
            }
        });


        /**
         * 监听刷新表格
         */
        form.on('submit(search)', function (data) {
            //console.log(JSON.stringify(data.field));
            table.reload('tableReload', {
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //监听工具条
        table.on('tool(popedomLay)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            //console.log(data.orderId)
            if (layEvent === 'toDetail') {
                layer.open({
                    type: 2,
                    title: '退货详情',
                    content: 'DDGL060/toReturnDetail.do',
                    area: ['500px', '500px'],
                    anim: 5,
                    isOutAnim: true,
                    maxmin: true,
                    resize: false,
                    moveOut: true,
                    zIndex: 99999,
                    btn: ['立即退货', '取消'],
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);  //巧妙的地方在这里哦
                        body.contents().find("#order_id").attr("value", data.orderId); //order_id 是子页面的属性id
                        body.contents().find("#user_name").attr("value", data.userName); //order_id 是子页面的属性id

                    }
                    , yes: function (index, layero) {         //按了弹出层的确定按钮时，这是将在父窗口中获取子窗口form标签里的所有值，并根据name名和值形成键值对json对象
                        /*console.log(layero);*/
                        //layer.alert('来到这里了'+index);
                        let body = layer.getChildFrame("body", index);
                        let data = {};
                        body.find("#my_form").serializeArray().forEach(function (item) {    //获取弹出层写下的数据，input，下拉框啊，之类的表单元素（即changefileform下的所有数据）
                            data[item.name] = item.value;   //根据表单元素的name属性来获取数据
                        });
                        //console.log(data);
                        $.ajax({
                            url: "DDGL060/toReturn.do",
                            type: "post",
                            data: data,
                            success: function (data) {
                                if (data.statusCode == '200') {
                                    //console.log("值返回成功")
                                    layer.msg(data.message, {icon: 6, time: 2000});
                                } else {
                                    layer.msg(data.message, {icon: 5, time: 2000});
                                }
                            }
                        }),
                        layer.close(index);//关闭弹窗
                    },
                    end: function () {
                        table.reload("tableReload");
                        return false;
                    }
                });
            }
        });


        //导出Excel
        /* $("#exportExcel").on("click", function () {
             layer.load(2, {time: 1000});
             window.location.href = "DDGL060/export.do?orderSn=" + $("#orderSn").val() + "&userName=" + $("#userName").val() + "&userCardNumber=" + $("#userCardNumber").val() + $("#receiverPhone").val() + "&receiverPhone=" + $("#orderState").val();
         });*/
    });
</script>
</body>
</html>
